    <body>
        <div class="x-nav">
            <span class="layui-breadcrumb">
              <a><cite>首页</cite></a>
              <a><cite>会员管理</cite></a>
              <a><cite>友情链接</cite></a>
            </span>
            <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"  href="javascript:location.replace(location.href);" title="刷新"><i class="layui-icon" style="line-height:30px">ဂ</i></a>
        </div>
        <div class="x-body">
            <form class="layui-form x-center" action="" style="width:70%">
                <div class="layui-form-pane" style="margin-top: 15px;">
                  <div class="layui-form-item">
                    <label class="layui-form-label">链接名</label>
                    <div class="layui-input-inline">
                      <input type="text" name="title"  placeholder="链接名" autocomplete="off" class="layui-input">
                    </div>
                    <label class="layui-form-label">URL</label>
                    <div class="layui-input-inline">
                      <input type="text" name="url"  placeholder="http://www.baidu.com" autocomplete="off" class="layui-input">
                    </div>
                    <div class="layui-input-inline" style="width:80px">
                        <button class="layui-btn"  lay-submit="" lay-filter="linkadd"><i class="layui-icon">&#xe608;</i>添加</button>
                    </div>
                  </div>
                </div> 
            </form>
            <xblock><button class="layui-btn layui-btn-danger" id="delAll"><i class="layui-icon">&#xe640;</i>批量删除</button><span class="x-right" style="line-height:40px">共有数据：88 条</span></xblock>
            <table class="layui-table">
                <thead>
                    <tr>
                        <th><input class="checkall" type="checkbox" name="" value=""></th>
                        <th>ID</th>
                        <th>链接名</th>
                        <th>url</th>
                        <th>排序</th>
                        <th>操作</th>
                    </tr>
                </thead>
                <tbody id="x-link">
                    <?php foreach ($link as $v) { ?>
                    <tr>
                        <td><input type="checkbox" value="<?php echo $v['id'] ?>" name="linkid"></td>
                        <td class="linkid" ><?php echo $v['id'] ?></td>
                        <td><?php echo $v['title'] ?></td>
                        <td><?php echo $v['url'] ?></td>
                        <td><?php echo $v['order'] ?></td>
                        <td class="td-manage">
                            <a title="编辑" href="javascript:;" onclick="link_edit('编辑','{:U('admin/sys/link_edit',array('id'=>$v['id']))}','4','','510')"
                            class="ml-5" style="text-decoration:none">
                                <i class="layui-icon">&#xe642;</i>
                            </a>
                            <a class="link_del" id="<?php echo $v['id'] ?>" title="删除" href="javascript:;" style="text-decoration:none">
                                <i class="layui-icon">&#xe640;</i>
                            </a>
                        </td>
                    </tr>
                    <?php } ?>
                </tbody>
            </table>

            <div id="page"></div>
        </div>
        <script>
            layui.use(['element','laypage','layer','form'], function(){
                $ = layui.jquery;//jquery
                lement = layui.element();//面包导航
                laypage = layui.laypage;//分页
                layer = layui.layer;//弹出层
                form = layui.form();//弹出层

                //监听提交
                form.on('submit(linkadd)', function(data){
                    // console.log(data);
                    //发异步，把数据提交给php
                    $.ajax({
                        url: '{:U('admin/sys/linkadd')}',
                        type: 'POST',
                        dataType: 'json',
                        data: data.field,
                    })
                    .done(function(respones) {
                        if (respones.error==0) {
                            layer.alert(respones.info, {icon: 6});
                            $('#x-link').prepend('<tr><td><input type="checkbox"value="'+respones.id+'"name=""></td><td>'+respones.id+'</td><td>'+data.field.title+'</td><td>'+data.field.url+'</td><td>0</td><td class="td-manage"><a title="编辑"href="javascript:;"onclick="link_edit(\'编辑\',\'link-edit.html\',\'4\',\'\',\'510\')"class="ml-5"style="text-decoration:none"><i class="layui-icon">&#xe642;</i></a><a title="删除"href="javascript:;"onclick="link_del(this,\'1\')"style="text-decoration:none"><i class="layui-icon">&#xe640;</i></a></td></tr>');
                        }else{
                            layer.msg(respones.info,{icon:1,time:1000});
                        };
                    })
                    .fail(function() {
                        console.log("error");
                    })
                    return false;
                });

                $('.link_del').click(function() {
                    link=$(this);
                    layer.confirm('确认要删除吗？',function(){
                        data = link.attr('id');
                        //发异步删除数据
                        $.ajax({
                            url: '{:U('admin/sys/delone')}',
                            type: 'post',
                            dataType: 'json',
                            data: {id:data}
                        })
                        .done(function(respones) {
                            if (respones.error==0) {
                                link.parents("tr").remove();
                                layer.msg(respones.info,{icon:1,time:1000});
                            }else{
                                layer.msg(respones.info,{icon:1,time:1000});
                            };
                        })
                        .fail(function() {
                            layer.msg(respones.info,{icon:1,time:1000});
                        })
                        return false;
                    })
                })

                $('.checkall').click(function(event) {
                    if ($('.checkall').prop('checked')) {
                        $('#x-link input').prop('checked', true)
                    }else{
                        $('#x-link input').prop('checked', false)
                    };
                });

                $('#delAll').click(function(event) {
                    layer.confirm('确认要删除吗？',function(index){
                        data= '';   //设定空字符串 
                        //将选中的ID 循环放进 data
                        for (var i = 0;i <$('#x-link input:checked').length; i++) {
                            data += $('#x-link input:checked').eq(i).val()+',';
                        };
                        //捉到所有被选中的，发异步进行删除
                        $.ajax({
                            url: '{:U('admin/sys/delall')}',
                            type: 'POST',
                            dataType: 'json',
                            data: {num:data},
                        })
                        .done(function(respones) {
                            if (respones.error==0) {
                                $('#x-link input:checked').parents("tr").remove();
                                layer.msg(respones.info, {icon: 1})
                            }else{
                                layer.msg(respones.info, {icon: 1})
                            };
                            
                        })
                        .fail(function() {
                            console.log("error");
                        })
                        return false;

                    });


                });
            })


            //批量删除提交
             function delAll () {
                layer.confirm('确认要删除吗？',function(index){
                    //捉到所有被选中的，发异步进行删除
                    layer.msg('删除成功', {icon: 1});
                });
             }
            
            

            // 编辑
            function link_edit (title,url,id,w,h) {
                x_admin_show(title,url,w,h); 
            }
            
            /*删除*/
            // function link_del(obj,id){

            // }
            </script>
    </body>
</html>